package com.test.demo;

/**
 * ${DESCRIPTION}
 *
 * @author muxiaoyu
 * @create 2017/05/24 11:45
 **/
class Dog001 {
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Dog001{" +
                "name='" + name + '\'' +
                '}';
    }

}

class Person001 {
    private String name;
    private Dog001 dog;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Dog001 getDog() {
        return dog;
    }

    public void setDog(Dog001 dog) {
        this.dog = dog;
    }

    @Override
    public String toString() {
        return "Person001{" +
                "name='" + name + '\'' +
                ", dog=" + dog +
                '}';
    }

    public void changeDog(Dog001 dog0011) {
        setDog(dog0011);
    }

    public void changeDog001(Dog001 dog001) {
        dog001 = new Dog001();
        dog001.setName("dog001");
    }
}

public class Demo001 {
    public static void main(String[] args) {
        Dog001 dog001 = new Dog001();
        dog001.setName("旺财！");
        Person001 person001 = new Person001();
        person001.setName("张三！");
        person001.setDog(dog001);
        //============1==============
        System.out.println("1:" + person001);
        //============2==============
        dog001.setName("狗蛋！");
        System.out.println("2:" + person001);
        //============3==============
        person001.changeDog001(dog001);
        System.out.println("3:" + person001);
        //============4==============
        Dog001 dog0011 = new Dog001();
        dog0011.setName("狗蛋二！");
        person001.changeDog(dog0011);
        System.out.println("4:" + person001);
    }
}
